package ua.kpi_java_training.tyshchenko.module2;

/**
 * Class does all the actions of the predator: move, considers the number of murders
 * and check appearance of new fish
 *
 * @author Vlad Tyshchenko
 * @version 1.1 3 June 2013
 */
public class Predator extends CreatureInHabitat {
    /**
     * LENGTH_STEP - amount of steps per cycle
     */
    final private int LENGTH_STEP = 3;
    final private int COUNT_KILLS = 5;
    private int countKills = 0;
    private Habitat habitat;

    /**
     * @param habitat
     */
    public Predator(Habitat habitat) {
        super(habitat);
        this.habitat = habitat;
    }

    public void move() {
        AbstractRand rand = new RandomNumber();
        super.move(rand.getStep(LENGTH_STEP));
    }

    /**
     * If predator kills victim - increase count of kills
     */
    public void addCountNewLife() {
        countKills++;
    }

    /**
     * @return - true if predator kills 'COUNT_KILLS' victims
     */
    public boolean checkBirth() {
        return (countKills % COUNT_KILLS == 0 && countKills != 0) ? true : false;
    }

    public CreatureInHabitat getNewFish() {
        return new Predator(habitat);
    }

    public KindOfCreatures getKeyCreature() {
        return KindOfCreatures.predator;
    }

}
